package com.agent.service.impl;

import java.util.List;
import java.util.Map;

import com.agent.entity.Dept;
import com.agent.page.EasyuiPage;
import com.agent.repository.DictMapper;
import com.agent.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.agent.entity.Dict;
import com.agent.service.IDictService;


@Service("dictService")
@Transactional
public class DictServiceImpl implements IDictService{
	
	@Autowired
	protected DictMapper dictMapper;

	public void delete(String id) {
		dictMapper.delete(id);
		
	}

	public List<Dict> getDictList(String id) {
		return dictMapper.getDict(id);
	}
	
	public Dict getDict(String code) {
		Dict dict = new Dict();
		dict.setCode(code);
		List<Dict> list = dictMapper.searchDict(dict);
		return list==null||list.size()==0l?null:list.get(0);
	}


	public void insert(Dict dict) {
		 dictMapper.insert(dict);
	}

	public List<Dict> searchAll() {
		return dictMapper.searchAll();
	}

	public EasyuiPage<Dict> searchDict(Integer page, Integer rows, Dict dict){
		PageHelper.startPage(page, rows,true, true, true);
		List<Dict> list = dictMapper.searchDict(dict);
		list.forEach(dict1 -> {
			if(Constants.SYSTEM_MODEL.equals(dict1.getCode())){
				dict1.setDictValue(Constants.getSystemModel(dict1.getDictValue()));
			}
		});
		EasyuiPage<Dict> pages = new EasyuiPage<Dict>();
		pages.setRows(list);
		PageInfo<Dict> pageinfo = new PageInfo<Dict>(list);
		pages.setTotal(pageinfo.getTotal());
		return pages;
	}

	public void update(Dict Dict) {
		dictMapper.update(Dict);
	}

	public DictMapper getDictMapper() {
		return dictMapper;
	}

	public void setDictMapper(DictMapper DictMapper) {
		this.dictMapper = DictMapper;
	}
	
	
	

}
